import torch.nn as nn


# 卷积→激活→池化
# 先激活，再池化，保证激活信息不被提前丢弃。

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(1, 10, 5)
        self.conv2 = nn.Conv2d(10, 20, 5)
        self.pool = nn.MaxPool2d(2)
        self.act = nn.ReLU()
        self.fc = nn.Linear(320, 10)

    def forward(self, x):
        x = self.pool(self.act(self.conv1(x)))  # ✅ Conv → ReLU → Pool
        x = self.pool(self.act(self.conv2(x)))  # ✅ Conv → ReLU → Pool
        x = x.view(x.size(0), -1)
        x = self.fc(x)
        return x


model = Net()
print(model)
# numel() 是 PyTorch 张量的一个方法，用于返回张量中元素的总数
# numel 是 "number of elements" 的缩写
print(model.conv1.weight.numel())
print(model.conv1.bias.numel())
